package com.bootdo.system.dao;

import com.bootdo.system.domain.UserAccountDetail;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserAccountDetailMapper {

	@Select("select * from tb_user_account_detail where id = #{id}")
	UserAccountDetail get(Long id);
	
	@Select("<script>" +
	"select * from tb_user_account_detail " + 
			"<where>" + 
			 "<if test=\"id != null and id != ''\">"+ "and id = #{id} " + "</if>" + 
	  		  "<if test=\"userId != null and userId != ''\">"+ "and userId = #{userId} " + "</if>" +
	  		  "<if test=\"orderId != null and orderId != ''\">"+ "and orderId = #{orderId} " + "</if>" +
			  "<if test=\"dealType != null and dealType != ''\">"+ "and dealType = #{dealType} " + "</if>" +
	  		  "<if test=\"dealTime != null and dealTime != ''\">"+ "and date_format(dealTime,'%Y-%m-%d') = #{dealTime} " + "</if>" +
		  	"</where>"+ 
			" <choose>" + 
	            "<when test=\"sort != null and sort.trim() != ''\">" + 
	                "order by ${sort} ${order}" + 
	            "</when>" + 
				"<otherwise>" + 
	                "order by id desc" + 
				"</otherwise>" + 
	        "</choose>"+
			"</script>")
	List<UserAccountDetail> list(Map<String,Object> map);
	
	
	@Insert("insert into tb_user_account_detail (`userId`, `point`, `dealTime`, `dealType`,`orderId`)"
	+ "values (#{userId}, #{point},#{dealTime}, #{dealType}, #{orderId})")
	@Options(useGeneratedKeys=true)
	int save(UserAccountDetail bComments);
	
	@Update("<script>"+ 
			"update tb_user_account_detail " + 
					"<set>" + 
		            "<if test=\"id != null\">`id` = #{id}, </if>" + 
                    "<if test=\"userId != null\">`userId` = #{userId}, </if>" + 
                    "<if test=\"point != null\">`point` = #{point}, </if>" + 
                    "<if test=\"dealTime != null\">`dealTime` = #{dealTime}, </if>" + 
                    "<if test=\"dealType != null\">`dealType` = #{dealType}, </if>" + 
                    "<if test=\"orderId != null\">`orderId` = #{orderId}, </if>" + 
          			"</set>" + 
					"where id = #{id}"+
			"</script>")
	int update(UserAccountDetail bComments);
	
	@Delete("delete from tb_user_account_detail where id =#{id}")
	int remove(Long id);
	
	@Delete("<script>"+ 
			"delete from tb_user_account_detail where id in " + 
					"<foreach item=\"id\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + 
						"#{id}" + 
					"</foreach>"+
			"</script>")
	int batchRemove(Integer[] ids);
}
